#ifndef THINK_THINK_CONTROLLER_H
#define THINK_THINK_CONTROLLER_H

static char* think_controller =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think;\n"
	"\n"
	"use think\\exception\\ValidateException;\n"
	"use traits\\controller\\Jump;\n"
	"\n"
	"class Controller\n"
	"{\n"
	"    use Jump;\n"
	"\n"
	"    /**\n"
	"     * @var \\think\\View 视图类实例\n"
	"     */\n"
	"    protected $view;\n"
	"\n"
	"    /**\n"
	"     * @var \\think\\Request Request 实例\n"
	"     */\n"
	"    protected $request;\n"
	"\n"
	"    /**\n"
	"     * @var bool 验证失败是否抛出异常\n"
	"     */\n"
	"    protected $failException = false;\n"
	"\n"
	"    /**\n"
	"     * @var bool 是否批量验证\n"
	"     */\n"
	"    protected $batchValidate = false;\n"
	"\n"
	"    /**\n"
	"     * @var array 前置操作方法列表\n"
	"     */\n"
	"    protected $beforeActionList = [];\n"
	"\n"
	"    /**\n"
	"     * 构造方法\n"
	"     * @access public\n"
	"     * @param Request $request Request 对象\n"
	"     */\n"
	"    public function __construct(Request $request = null)\n"
	"    {\n"
	"        $this->view    = View::instance(Config::get(\'template\'), Config::get(\'view_replace_str\'));\n"
	"        $this->request = is_null($request) ? Request::instance() : $request;\n"
	"\n"
	"        // 控制器初始化\n"
	"        $this->_initialize();\n"
	"\n"
	"        // 前置操作方法\n"
	"        if ($this->beforeActionList) {\n"
	"            foreach ($this->beforeActionList as $method => $options) {\n"
	"                is_numeric($method) ?\n"
	"                $this->beforeAction($options) :\n"
	"                $this->beforeAction($method, $options);\n"
	"            }\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 初始化操作\n"
	"     * @access protected\n"
	"     */\n"
	"    protected function _initialize()\n"
	"    {\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 前置操作\n"
	"     * @access protected\n"
	"     * @param  string $method  前置操作方法名\n"
	"     * @param  array  $options 调用参数 [\'only\'=>[...]] 或者 [\'except\'=>[...]]\n"
	"     * @return void\n"
	"     */\n"
	"    protected function beforeAction($method, $options = [])\n"
	"    {\n"
	"        if (isset($options[\'only\'])) {\n"
	"            if (is_string($options[\'only\'])) {\n"
	"                $options[\'only\'] = explode(\',\', $options[\'only\']);\n"
	"            }\n"
	"\n"
	"            if (!in_array($this->request->action(), $options[\'only\'])) {\n"
	"                return;\n"
	"            }\n"
	"        } elseif (isset($options[\'except\'])) {\n"
	"            if (is_string($options[\'except\'])) {\n"
	"                $options[\'except\'] = explode(\',\', $options[\'except\']);\n"
	"            }\n"
	"\n"
	"            if (in_array($this->request->action(), $options[\'except\'])) {\n"
	"                return;\n"
	"            }\n"
	"        }\n"
	"\n"
	"        call_user_func([$this, $method]);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 加载模板输出\n"
	"     * @access protected\n"
	"     * @param  string $template 模板文件名\n"
	"     * @param  array  $vars     模板输出变量\n"
	"     * @param  array  $replace  模板替换\n"
	"     * @param  array  $config   模板参数\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function fetch($template = \'\', $vars = [], $replace = [], $config = [])\n"
	"    {\n"
	"        return $this->view->fetch($template, $vars, $replace, $config);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 渲染内容输出\n"
	"     * @access protected\n"
	"     * @param  string $content 模板内容\n"
	"     * @param  array  $vars    模板输出变量\n"
	"     * @param  array  $replace 替换内容\n"
	"     * @param  array  $config  模板参数\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function display($content = \'\', $vars = [], $replace = [], $config = [])\n"
	"    {\n"
	"        return $this->view->display($content, $vars, $replace, $config);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 模板变量赋值\n"
	"     * @access protected\n"
	"     * @param  mixed $name  要显示的模板变量\n"
	"     * @param  mixed $value 变量的值\n"
	"     * @return $this\n"
	"     */\n"
	"    protected function assign($name, $value = \'\')\n"
	"    {\n"
	"        $this->view->assign($name, $value);\n"
	"\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 初始化模板引擎\n"
	"     * @access protected\n"
	"     * @param array|string $engine 引擎参数\n"
	"     * @return $this\n"
	"     */\n"
	"    protected function engine($engine)\n"
	"    {\n"
	"        $this->view->engine($engine);\n"
	"\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置验证失败后是否抛出异常\n"
	"     * @access protected\n"
	"     * @param bool $fail 是否抛出异常\n"
	"     * @return $this\n"
	"     */\n"
	"    protected function validateFailException($fail = true)\n"
	"    {\n"
	"        $this->failException = $fail;\n"
	"\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证数据\n"
	"     * @access protected\n"
	"     * @param  array        $data     数据\n"
	"     * @param  string|array $validate 验证器名或者验证规则数组\n"
	"     * @param  array        $message  提示信息\n"
	"     * @param  bool         $batch    是否批量验证\n"
	"     * @param  mixed        $callback 回调方法（闭包）\n"
	"     * @return array|string|true\n"
	"     * @throws ValidateException\n"
	"     */\n"
	"    protected function validate($data, $validate, $message = [], $batch = false, $callback = null)\n"
	"    {\n"
	"        if (is_array($validate)) {\n"
	"            $v = Loader::validate();\n"
	"            $v->rule($validate);\n"
	"        } else {\n"
	"            // 支持场景\n"
	"            if (strpos($validate, \'.\')) {\n"
	"                list($validate, $scene) = explode(\'.\', $validate);\n"
	"            }\n"
	"\n"
	"            $v = Loader::validate($validate);\n"
	"\n"
	"            !empty($scene) && $v->scene($scene);\n"
	"        }\n"
	"\n"
	"        // 批量验证\n"
	"        if ($batch || $this->batchValidate) {\n"
	"            $v->batch(true);\n"
	"        }\n"
	"\n"
	"        // 设置错误信息\n"
	"        if (is_array($message)) {\n"
	"            $v->message($message);\n"
	"        }\n"
	"\n"
	"        // 使用回调验证\n"
	"        if ($callback && is_callable($callback)) {\n"
	"            call_user_func_array($callback, [$v, &$data]);\n"
	"        }\n"
	"\n"
	"        if (!$v->check($data)) {\n"
	"            if ($this->failException) {\n"
	"                throw new ValidateException($v->getError());\n"
	"            }\n"
	"\n"
	"            return $v->getError();\n"
	"        }\n"
	"\n"
	"        return true;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif
